﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Robot.DeviceTestTools
{
    public partial class FormElecMachines : Form
    {
        #region 公共变量

        #endregion

        #region 构造函数

        public FormElecMachines()
        {
            InitializeComponent();
        }

        #endregion

        #region 窗体事件

        /// <summary>
        /// 窗体初始化加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormMain_Load(object sender, EventArgs e)
        {
            Initialization();
        }

        /// <summary>
        /// 开始实验 按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_StartExp_Click(object sender, EventArgs e)
        {
            (bool, string) result = Global.ElecMachines.StartExp(comboBox_ExpName.SelectedIndex);
            MessageBox.Show(result.Item2);
        }

        /// <summary>
        /// 结束实验 按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_StopExp_Click(object sender, EventArgs e)
        {
            (bool, string) result = Global.ElecMachines.StopExp();
            MessageBox.Show(result.Item2);
        }

        #endregion

        #region 自定义方法

        #region 页面功能初始化

        /// <summary>
        /// 页面功能初始化
        /// </summary>
        public void Initialization()
        {
            // 初始化可用实验列表
            List<string> ExperimentName = Global.ElecMachines.GetExperimentList();
            ExperimentName.ForEach(item =>
            {
                comboBox_ExpName.Items.Add($"{item}");
            });
            comboBox_ExpName.SelectedIndex = 0;

            // 初始化可用设备
            try
            {
                (bool, string) isSuccess = Global.ElecMachines.InitConnect();
                MessageBox.Show(isSuccess.Item2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        #endregion

        #endregion

    }
}
